import React from 'react';
import {
  Form,
  Input,
  Button,
  Table,
  Icon,
  Radio,
  InputNumber,
  Checkbox,
  Modal,
  message,
  notification,
  Affix,
  Upload,
  Select
} from 'antd';

import InnerTable from 'components/DBTable/InnerTable.js';
import ajax from '../../../utils/ajax';

const FormItem = Form.Item;
const ButtonGroup = Button.Group;
const Option = Select.Option;

var _this;

/**
 * 内部表格组件
 */
class AppPushMsgInnerTable extends InnerTable {


  /**
   * 构造器，好像是用来初始化的？
   * @param props
   */
  constructor(props) {
    super(props);
    this.state = {
      ...this.state,
      upOpt: ['OPTION_SAVE'],
    };
    // 0 返回file和image 
    // 1 file 
    // 2 image
    this.responseStatus = 2;
  }


  /**
   * 这里好像是用来配置那些按钮之类的
   * @returns {Array}
   */
  prepareToolBar = function () {

    let isButtondisabled = false;

    if (this.state.selectedRowKeys.length > 0) {  // 是否选择
      isButtondisabled = true;
    }

    if (this.state.selectedRowKeys.length > 1) {  // 是否选择了多项
      isButtondisabled = false;
    }

  }

  onImageFileChange = (info) => {
    let fileList = info.fileList;

    console.log("fileList 里面的数据是", fileList);

    if (fileList.length > 1) {
      fileList = fileList.slice(-1); //最多只能有一个文件
    }

    if (info.file.response) {
      fileList = fileList.map((file) => {
        file.url = file.response.data.imgUrl;
        return file;
      });
      let id = info.file.response.data.id;
      this.props.form.setFieldsValue({imageId: id});
    }

    this.setState({fileList: fileList});
  }

  /**
   * 点击新增之前处理一下数据
   * @param obj
   */
  handleInsertBefore = () => {
    delete this.state.fileList; //删除上传框那里的文件
  }

  preDealTableData=(obj,newObj)=>{
    let systemMsgTitle = obj.systemMsgTitle;
    if(!systemMsgTitle){
      newObj.systemMsgTitle = obj.title;
    }
  }
  /**
   * 请求之前，先处理数据
   * @param obj
   * @returns {*}
   */
  handleData = (data) => {
    let userIds = data.params.userIds;
    console.log("data 里面的数据是", data);

    //推送的用户
    if (userIds) {
      let ids = "";
      for (let i = 0; i < userIds.length; i++) {
        ids += (userIds[i] + ",");
      }

      data.params.userIds = ids.substring(0, ids.length - 1);
    }

    let url = data.params.directUrl;
    if(!url){
      data.params.directUrl = "heatedloan://actiontype=100";
    }

    let title = data.params.title;
    if(!title) {
      data.params.title = "秒借贷";
    }

    let systemMsgTitle = data.params.systemMsgTitle;
    if(!systemMsgTitle){
      data.params.systemMsgTitle = data.params.title;
    }

    //客户端类型
    let clientType = data.params.clientType;
    if (clientType) {
      if (clientType.length == 2) {
        data.params.android = 1;
        data.params.ios = 1;
      } else if (clientType == 1) {
        if(clientType[0] == "ios"){
          data.params.ios = 1;
        }else{
          data.params.android = 1;
        }
      }

      delete data.params.clientType;
    }

    //是否是系统消息
    data.params.msgType = data.params.msgType ? data.params.msgType : 0;

    //如果是系统消息，判断消息内容是否为空，为空则直接取推送的消息数据
    if(data.params.msgType == 1){
      if(!data.params.systemContent){
        data.params.systemContent = data.params.content;
      }
    }

    //推送时间，这里如果不转换，就会造成不去请求的错误
    let pushTimeStr = data.params.pushTimeStr;
    if(pushTimeStr){
      data.params.pushTimeStr = pushTimeStr.format('YYYY-MM-DD HH:mm:ss');
    }

    return data;

  }
}

export default AppPushMsgInnerTable;
